// pages/filing/relationships/relationships.js
import {
  deleteFamilyMember,
  getFamilyMemberApi,
  updateFamilyArchiveStatus
} from "../../../services/filing/filing"
import {
  GETSTORAGE
} from "../../../services/storage/storage"
Page({
  data: {
    list: [],
    btnFlag: false,
    userFamilyMemberId: ''
  },
  getInitData() {
    const familyId = GETSTORAGE('familyId')
    getFamilyMemberApi({
      familyId: familyId
    }).then(res => {
      console.log(res, "获取家庭成员");
      this.setData({
        list: res.data.data,
      })
    })
  },
  update() {
    const familyId = GETSTORAGE('familyId')
    updateFamilyArchiveStatus({
      familyId: familyId,
      status: "health_manage"
    }).then(res => {
      console.log(res);
    })
  },
  skip() {
    this.update()
    this.setData({
      showWarnConfirm: false
    });
    wx.navigateTo({
      url: '/pages/filing/health-management/healt-hmanagement'
    })
  },
  return () {
    wx.navigateBack({
      delta: 1,
    })
  },
  continueAdd() {
    this.setData({
      showWarnConfirm: true,
    });
    wx.navigateTo({
      url: '/pages/filing/family/family'
    })
  },
  deleteFamilyMember(e) {
    const familyMemberId = e.currentTarget.dataset.familymemberid
    deleteFamilyMember({
      familyMemberId
    }).then(res => {
      res.data.code == 200 ? this.getInitData() : ''
    })


  },
  onLoad(options) {
    if (options.relationships && options.relationships == 'relationships') {
      this.setData({
        btnFlag: true
      })
    } else {
      this.setData({
        btnFlag: false
      })
    }
    const userFamilyMemberId = GETSTORAGE('familyMemberId')
    this.setData({
      userFamilyMemberId
    })
    this.getInitData()
  },


  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})